const KoaRouter = require('@koa/router')
const { create, getUserInfo, signToken, updateUserInfo } = require('../controller/userController.js')
const { verifyUser, hanlPassword, verifyUserInfo, verifyExistUser } = require('../middleware/userMiddleware.js')
const { wxLoginByCode } = require('../middleware/loginMiddleware.js')
const userRouter = new KoaRouter({prefix:'/user'})

// 游客登录
userRouter.get('/visitor' ,  create )

// 查询用户信息
userRouter.post('/getUserinfo' , getUserInfo )

// 绑定用户名和密码  先验证此时用户信息是否已经绑定过  在验证用户是否存在
userRouter.post('/register' , verifyUserInfo , verifyExistUser  ,  hanlPassword ,  signToken)

// 用户名登录
userRouter.post('/userNameLogin' ,  verifyUser )

// 微信登录
userRouter.post('/wxLogin' , wxLoginByCode , updateUserInfo )

module.exports = userRouter